#!/usr/bin/env python

from optparse import OptionParser
from lex.tokenizer import generate_tokens
from lex.token import tok_name

def print_tokens(fp):
    f = open(fp, 'rb')
    for token in generate_tokens(f.readline):
        tk, name, (ls, cs), (le, ce), line = token
        print tok_name[tk], name, '%s:%s-%s:%s' % (ls, cs, le, ce)
    f.close()

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option('-f', '--file',
                      dest='filename',
                      metavar='FILE')
    (options, args) = parser.parse_args()
    fp = getattr(options, 'filename')
    if fp:
        print print_tokens(fp)
    else:
        print parser.format_help()


